package com.rmt.www.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.rmt.www.dao.ProjectDao;
import com.rmt.www.dao.UserDao;
import com.rmt.www.vo.Project;
import com.rmt.www.vo.User;


public class LoginAction extends ActionSupport{
	private String username;
	private String password;
	private UserDao userDao;
	
	public UserDao getUserDao() {
		return userDao;
	}
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String execute(){
		User u=userDao.getUser(username);
		if(u==null){
			this.addFieldError("loginFailed", "this account doesn't exist!");
			return "fail";
		}
		if(!u.getPassword().equals(password)){
			this.addFieldError("loginFailed", "invalid password!");
			return "fail";
		}
		ActionContext.getContext().getSession().put("currentUser", u);
		String type=u.getType();
		if(type.equals("admin")){
			return "admin";
		}else{
			return "others";
		}
	}
	
}
